import SignInApi from '@/sheep/api/member/signin';
import { reactive } from 'vue';
const signData = reactive(({}))

// 发起签到
export  function useSign() {
  return {
    signData,onSign,getSignInfo,getSignConfigList
  }
}
async function onSign() {
  const { code, data } = await SignInApi.createSignInRecord();
  if (code !== 0) {
    return;
  }
  signData.signResult = data;
  // 重新获得签到信息
  await getSignInfo();
}

// 获得个人签到统计
async function getSignInfo() {
  const { code, data } = await SignInApi.getSignInRecordSummary();
  if (code !== 0) {
    return;
  }
  signData.signInfo = data;
}

// 获取签到配置
async function getSignConfigList() {
  const { code, data } = await SignInApi.getSignInConfigList();
  if (code !== 0) {
    return;
  }
  signData.signConfigList = data;
  if (data.length > 0) {
    signData.maxDay = data[data.length - 1].day;
  }
}